<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>page</title>

    <link rel="stylesheet" href="../bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../css/forPage.css">
    <link rel="stylesheet" type="text/css" href="../font-awesome-4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">

    <script src="../JQuery/JQuery-2.1.4.min.js"></script>
    <script src="../bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

    <style type="text/css">
        table {
            text-align: center; /*设置水平居中*/
            vertical-align: middle; /*设置垂直居中*/
            font-size: 12px;
        }

        th {
            text-align: center; /*设置水平居中*/
            vertical-align: middle; /*设置垂直居中*/
            font-size: 14px;
        }
    </style>

</head>
<!--<body style="margin: 20px">-->

<body class="hold-transition skin-blue layout-top-nav">
<div class="main-header">
    <div class="navbar navbar-static-top">
        <div class="navbar-header">
            <a href="#" class="navbar-brand"><b>我的云盘</b></a>
        </div>
    </div>
</div>

<div class="content-wrapper">
    <div class="content" style="min-height: 560px">
        <div class="box-header with-border">
            <i class="fa fa-user form-inline pull-left"></i>
            <span style="margin-right: 5rem;font-size: 25px" class="form-inline pull-left">username:
                    <span id="usernameRecord"></span>
                </span>

            <span style="font-size: 25px" class="form-inline pull-left">
                    currentPath:  <span id="currentPathRecord"></span>
                </span>

            <span class="form-inline pull-right">
                    <button type="button" name=""
                            class="btn btn-default pull-right" id="exit">
                        <i class="fa fa-outdent"></i> 退出登录
                    </button>
                </span>

        </div>

        <div class="box-body">
            <div class="box-header with-border">

                <button type="button" name="add"
                        class="btn btn-default pull-left " id="back">
                    <i class="fa fa-backward"></i> Back
                </button>

                <button type="button" name="add"
                        class="btn btn-default pull-left" onclick="showNewDirectory()">
                    <i class="fa fa-file"></i> 新建目录
                </button>

                <div class="form-inline pull-left">
                    <button type="button" name="search" id="search-btn"
                            class="btn btn-default pull-right searchBtn" title="搜索">
                        <i class="fa fa-search"></i>
                    </button>
                    <input type="text"
                           class="form-control pull-left name-search position-search"
                           id="keyword" placeholder="fileName"/>
                </div>

                <form id="uploadForm" enctype="multipart/form-data">
                    <button id="upload" type="button" class="btn btn-default form-inline pull-right">
                        <i class="fa fa-cloud"></i>upload
                    </button>

                    <input id="file" type="file" name="file" class="form-inline pull-right"/>
                </form>

            </div>

            <table width="100%" id="filesDisplay" class="table table-bordered">
                <thead>
                <tr>
                    <!--                        <th width="20%"><img class="img-lg img-rounded img-bordered" src="../images/1.jpeg"></th>-->
                    <!--                        <th width="20%"><img class="img-lg img-rounded img-bordered" src="../images/2.jpeg"></th>-->
                    <!--                        <th width="20%"><img class="img-lg img-rounded img-bordered" src="../images/2.jpeg"></th>-->
                    <!--                        <th width="20%"><img class="img-lg img-rounded img-bordered" src="../images/2.jpeg"></th>-->
                    <!--                        <th width="20%"><img class="img-lg img-rounded img-bordered glyphicon-resize-small" src="../images/2.jpeg"></th>-->
<!--                    <th width="33%"></th>-->
<!--                    <th width="33%"></th>-->
<!--                    <th width="33%"></th>-->
                </tr>
                </thead>
                <tbody id="">
                </tbody>
            </table>

        </div>


    </div>

</div>

<hr>
<br><br>

<div class="contextmenu" id="directory_memu">
    <ul>
        <li><a onclick="copyFile()">复制</a></li>
        <li><a onclick="cutFile()">剪切</a></li>
        <li><a onclick="deleteFile()">删除</a></li>
        <li><a onclick="renameFile()">重命名</a></li>
        <li><a onclick="showFileDetail()">详情信息</a></li>
    </ul>
</div>

<div class="contextmenu" id="file_memu">
    <ul>
        <li><a onclick="copyFile()">复制</a></li>
        <li><a onclick="cutFile()">剪切</a></li>
        <li><a onclick="deleteFile()">删除</a></li>
        <li><a onclick="renameFile()">重命名</a></li>
        <li><a onclick="showFileDetail()">详情信息</a></li>
        <li><a onclick="installFile()">下载</a></li>
    </ul>
</div>

<div class="contextmenu" id="common_memu">
    <ul>
        <li><a onclick="showNewDirectory()">新建目录</a></li>
        <li><a onclick="pasteFile()">粘贴</a></li>
    </ul>
</div>

<hr>

<!-- 查看文件详情信息模态框 -->
<div class="modal fade" id="fileInfoDetailModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    文件信息
                </h4>
            </div>
            <div class="modal-body">

                <div>
                    <label>文件名:</label>
                    <span id="file-name"></span>
                </div>

                <div>
                    <label>创建时间:</label>
                    <span id="file-date"></span>
                </div>

                <div>
                    <label>文件类型:</label>
                    <span id="file-type"></span>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="fileInfoDetailModalClose()">
                        close
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>

<!-- 新建目录，模态框 -->
<div class="modal fade" id="newDirectoryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    创建目录
                </h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-2 control-label strong">目录名称</label>
                    <div>
                        <div class="col-md-pull-12">
                            <input class="form-control" type="text" id="newDirectoryPath"/>
                        </div>
                        <div class="col-md-2">
                            <span style="color: #F00; fontsize: 30px"></span>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="confirmNewDir()">
                            创建
                        </button>
                        <button type="button" class="btn btn-default" data-dismiss="modal"
                                onclick="newDirectoryModalClose()">关闭
                        </button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    </div>
</div>

<!-- 文件重命名，模态框 -->
<div class="modal fade" id="fileRenameModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    文件重命名
                </h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-2 control-label strong">new_name:</label>
                    <div>
                        <div class="col-md-pull-12">
                            <input class="form-control" type="text" id="newFileName"/>
                        </div>
                        <div class="col-md-2">
                            <span style="color: #F00; fontsize: 30px"></span>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" onclick="confirmRename()">
                            确定
                        </button>
                        <button type="button" class="btn btn-default" data-dismiss="modal"
                                onclick="fileRenameModalClose()">关闭
                        </button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    </div>
</div>

<script type="text/javascript">

    //搜索文件信息
    $('#search-btn').on('click', function () {
        var key = $('#keyword').val();
        alert(key);
        // findFile(key);
    })

    // 搜索文件
    function findFile(key) {
        var d = {
            "key": key,
        };
        var url = "";
        $.ajax({
            type: "post",
            url: url,
            data: d,
            success: function (data) {
                if (data.status == "ok") {
                    getFiles(data.filePath);
                }
            }
        })

    }

    // 文件重命名弹窗 点击 确定
    function confirmRename(){// oldName
        let oldName = sessionStorage.getItem('oldName');
        let newName = sessionStorage.getItem('currentPath') + "/" + $('#newFileName').val();

        // alert(oldName + " : " + newName);
        var d = {
            "oldName":oldName,
            "newName":newName,
        }
        var url = "/fileRename";
        $.ajax({
            type:"post",
            data:d,
            url:url,
            success:function (data){
                if(data.status == "ok"){
                    sessionStorage.removeItem('oldName');
                    $('#fileRenameModal').modal('hide');
                    getFiles(sessionStorage.getItem("currentPath"));
                }else{
                    alert("服务器异常.....");
                }
            }
        })
    }

    // 点击右键目录中文件重命名
    function renameFile(){
        let currentPath = sessionStorage.getItem("currentPath");
        let fileStr = document.getElementById('file_memu').getAttribute('fileName');
        let direcStr = document.getElementById('directory_memu').getAttribute('fileName');
        if(fileStr == null){
            let oldName = currentPath+"/"+direcStr;
            sessionStorage.setItem("oldName",oldName);
            $('#fileRenameModal').modal('show');
        }else if(direcStr == null){
            let oldName = currentPath+"/"+fileStr;
            sessionStorage.setItem("oldName",oldName);
            $('#fileRenameModal').modal('show');
        }else {
            alert("8456123 error!");
        }
    }

    // 关闭重命名模态框
    function fileRenameModalClose() {
        $('#fileRenameModal').modal('hide');
        $('#newFileName').val('');
    }

    // 粘贴文件
    function pasteFile(){
        let oldPath = sessionStorage.getItem('oldPath');

        // 没有复制文件
        if(oldPath == null){
            return;
        }

        let newPath = sessionStorage.getItem('currentPath');
        let d = {
            "oldPath":oldPath,
            "newPath":newPath,
        }

        let operate_type = sessionStorage.getItem('paste_operate_type');
        let url;
        if(operate_type == 'copy'){
            url = "/copyToElsePlace";
        }
        else {
            url = "/moveToElsePlace";
        }

        $.ajax({
            type:"post",
            data:d,
            url:url,
            success:function (data){
                if(data.status == "ok"){
                    sessionStorage.removeItem('oldPath');
                    sessionStorage.removeItem('paste_operate_type');
                    showFiles(data.fileList);
                }else{
                    alert("服务器异常.....");
                }
            }
        })

    }

    // 剪切文件（移动文件）
    function cutFile(){
        // alert("cutFile");
        let currentPath = sessionStorage.getItem("currentPath");
        let fileStr = document.getElementById('file_memu').getAttribute('fileName');
        let direcStr = document.getElementById('directory_memu').getAttribute('fileName');
        if(fileStr == null){
            let oldPath = currentPath+"/"+direcStr;
            sessionStorage.setItem("oldPath",oldPath);
            sessionStorage.setItem("paste_operate_type","cut");
        }else if(direcStr == null){
            let oldPath = currentPath+"/"+fileStr;
            sessionStorage.setItem("oldPath",oldPath);
            sessionStorage.setItem("paste_operate_type","cut");
        }else {
            alert("8456123 error!");
        }
    }

    // 复制文件夹或目录
    function copyFile() {
        let currentPath = sessionStorage.getItem("currentPath");
        let fileStr = document.getElementById('file_memu').getAttribute('fileName');
        let direcStr = document.getElementById('directory_memu').getAttribute('fileName');
        if(fileStr == null){
            let oldPath = currentPath+"/"+direcStr;
            sessionStorage.setItem("oldPath",oldPath);
            sessionStorage.setItem("paste_operate_type","copy");
        }else if(direcStr == null){
            let oldPath = currentPath+"/"+fileStr;
            sessionStorage.setItem("oldPath",oldPath);
            sessionStorage.setItem("paste_operate_type","copy");
        }else {
            alert("8456123 error!");
        }
    }

    // 新建目录模态框确定新建
    function confirmNewDir() {
        var filename = document.getElementById("newDirectoryPath").value;
        var path = sessionStorage.getItem("currentPath");
        var d = {
            "currentPath": path,
            "filename": filename,
        }
        var url = "/makeDir";
        $.ajax({
            type: "post",
            url: url,
            data: d,
            success: function (data) {
                // 清空之前的路径
                jQuery('#dirPath').val('');

                if (data.status == "isexist") {
                    alert("该文件夹已存在！")
                } else {
                    alert("创建成功！");
                    newDirectoryModalClose();
                    showFiles(data.fileList);
                    // var dispaly = document.getElementById("filesDisplay");
                    // dispaly.innerHTML = "";
                    // for (var i = 0;i<data.fileList.length;i++){
                    //     var per = data.fileList[i];
                    //     var row = document.createElement('div');
                    //     row.innerHTML="<div>"+ per.fileName + "  -----  "+per.date + "  -----  "+ per.fileType+"</div>";
                    //     dispaly.appendChild(row);
                    // }
                }
            }
        })

    }

    // 打开新建目录模态框
    function showNewDirectory() {
        $('#newDirectoryModal').modal('show');
    }

    // 关闭新建目录模态框
    function newDirectoryModalClose() {
        $('#newDirectoryModal').modal('hide');
        $('#newDirectoryPath').val('');
    }

    //打开文件详情模态框
    function showFileDetail() {
        $('#fileInfoDetailModal').modal('show');
    }

    // 关闭文件详情模态框
    function fileInfoDetailModalClose() {
        $('#fileInfoDetailModal').modal('hide');
    }

    // 从本地采用form-data 上传文件
    jQuery('#upload').on('click', function () {
        var filename = jQuery('#file').val();
        if (filename == "") {
            return;
        }

        var path = sessionStorage.getItem("currentPath");
        var formData = new FormData();

        formData.append('file', $('#file')[0].files[0]);
        formData.append('filename', filename);
        formData.append('path', path);
        $.ajax({
            url: '/upload',
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.status == "ok") {
                    showFiles(data.fileList);
                    alert("文件上传成功！")
                    jQuery('#file').val('');
                } else if (data.status == "isExist") {
                    alert("文件已存在！")
                    jQuery('#file').val('');
                } else {
                    alert("服务器异常！")
                    jQuery('#file').val('');
                }
            }
        })

    })

    // 设置监听器 关闭浏览器自带的右键菜单
    document.addEventListener("contextmenu", (e) => {
        var e = e || window.event;
        e.preventDefault();  //阻止系统右键菜单 IE8-不支持
    });

    // 鼠标右键点击空白地方显示 common_menu
    document.oncontextmenu = function (mouse){
        // alert("oncontextmenu...");
        let directory_memu = document.getElementById('directory_memu');
        let file_memu = document.getElementById('file_memu');
        let common_menu = document.getElementById('common_memu');

        // 如果右键点击的是图片，则不显示 common_menu
        var flag = false;
        if(directory_memu.style.display == 'block' || file_memu.style.display == 'block'){
            flag = true;
        }

        if(!flag){
            if(common_menu.style.display != 'block'){
                common_menu.style.display = 'block';
                common_memu.style.left = mouse.x + 'px';
                common_memu.style.top = mouse.y + 'px';

            }else{
                common_memu.style.left = mouse.x + 'px';
                common_memu.style.top = mouse.y + 'px';
            }
        }
    }

    // 鼠标点击后，关闭菜单
    document.onclick = function () {
        let directory_memu = document.getElementById('directory_memu');
        let file_memu = document.getElementById('file_memu');
        let common_menu = document.getElementById('common_memu');

        directory_memu.style.display = 'none';
        file_memu.style.display = 'none';
        common_menu.style.display = 'none';
    }

    // 右键显示显示菜单
    function menuInfo(info) {
        // alert("menuinfo.....");
        let type = info.getAttribute('data-type');
        let fileName = info.getAttribute('filename');
        let directory_memu = document.getElementById('directory_memu');
        let file_memu = document.getElementById('file_memu');
        if (type == "directory") {
            // 显示菜单
            directory_memu.style.display = 'block';

            directory_memu.setAttribute('fileName',fileName);
            file_memu.removeAttribute('fileName');

            // 获取鼠标点击位置
            directory_memu.style.left = info.x + 'px';
            directory_memu.style.top = info.y + 'px';
        } else if (type == "file") {
            // 显示菜单
            file_memu.style.display = 'block';

            file_memu.setAttribute('fileName',fileName);
            directory_memu.removeAttribute('fileName');

            // 获取鼠标点击位置
            file_memu.style.left = info.x + 'px';
            file_memu.style.top = info.y + 'px';
        } else { // 点击空白地方
            let common_memu = document.getElementById('common_memu');
            // 显示菜单
            common_memu.style.display = 'block';

            // 获取鼠标点击位置
            common_memu.style.left = info.x + 'px';
            common_memu.style.top = info.y + 'px';
        }

        sessionStorage.setItem("file-name", info.getAttribute("filename"));

        document.getElementById('file-name').innerText = info.getAttribute('filename');
        document.getElementById('file-date').innerText = info.getAttribute('date');
        document.getElementById('file-type').innerText = info.getAttribute('data-type');
    }

    // 获取当前页面的所有文件
    function getFiles(path) {
        var d = { // json 数据类型
            "currentPath": path,
        }
        var url = "/getFiles";
        $.ajax({
            type: "post",
            url: url,
            data: d,
            success: function (data) {
                if(data.status == "ok"){
                    showFiles(data.fileList);
                }else {
                    alert("服务器正忙.....")
                }
            }
        })
    }

    // 删除选定文件
    function deleteFile() {
        if (confirm("是否确定删除文件？")) {
            var d = {
                "path": sessionStorage.getItem("currentPath"),
                "fileName": sessionStorage.getItem("file-name")
            }
            var url = "/deleteFile";
            $.ajax({
                type: "post",
                data: d,
                url: url,
                success: function (data) {
                    if (data.status == 'ok') {
                        showFiles(data.fileList);
                    }
                }
            })
        }
    }

    // 加载页面时，更新信息
    jQuery(document).ready(function () {
        document.getElementById("usernameRecord").innerText = sessionStorage.getItem("username");
        document.getElementById("currentPathRecord").innerText = sessionStorage.getItem("currentPath");
        getFiles(sessionStorage.getItem("currentPath"));
    })

    // 点击文件或者文件夹图标响应函数
    function fileHandle(info) {
        var type = info.getAttribute('data-type');
        var d = {
            "fileName": info.getAttribute('filename'),
            "currentPath": sessionStorage.getItem("currentPath"),
        }
        if (type == 'directory') {
            var url = "/fileHandle";
            $.ajax({
                type: "post",
                url: url,
                data: d,
                success: function (data) {
                    if (data.status == 'ok') {
                        sessionStorage.setItem("currentPath", data.currentPath);
                        document.getElementById("currentPathRecord").innerText = sessionStorage.getItem("currentPath");
                        showFiles(data.fileList);
                    } else {
                        alert("服务器忙，请稍后再试！");
                    }
                }
            })
        } else if (type == 'file') {
            // if (confirm("确定下载文件？")) {
            //     // 下载文件 直接使用同步调用
            //     var fileName = info.getAttribute('filename');
            //     var currentPath = sessionStorage.getItem("currentPath");
            //     window.location.href = "/download?fileName=" + fileName + "&currentPath=" + currentPath;
            // }
        }


    }

    // 下载文件
    function installFile(){
        if (confirm("确定下载文件？")) {
            // 下载文件 直接使用同步调用
            let fileName = document.getElementById('file_memu').getAttribute('fileName');
            let currentPath = sessionStorage.getItem("currentPath");
            let myhref = "/download?fileName=" + fileName + "&currentPath=" + currentPath;
            // alert(myhref);
            window.location.href = myhref;
        }
    }

    // 图形显示文件和文件夹
    function showFiles(fileList) {
        // var dispaly = document.getElementById("filesDisplay");
        // dispaly.innerHTML = "";
        // for (var i = 0;i<fileList.length;i++){
        //     var per = fileList[i];
        //     var row = document.createElement('div');
        //
        //     if(per.fileType == 'directory'){
        //         row.innerHTML="<span><img src=\"../image/img_1.png\" width=\"75\" height=\"75\" data-type=\"directory\" filename="
        //             + per.fileName+ " date="+per.date+" oncontextmenu=\"menuInfo(this)\" onclick=\"fileHandle(this)\"></img><p>"+per.fileName+"</p><span>";
        //     }
        //
        //     if(per.fileType == 'file'){
        //         row.innerHTML="<span><img src=\"../image/img.png\" width=\"75\" height=\"75\" data-type=\"file\" filename="
        //             +per.fileName+" date="+per.date+" oncontextmenu=\"menuInfo(this)\" onclick=\"fileHandle(this)\"></img><p>"+per.fileName+"</p><span>";
        //     }
        //     dispaly.appendChild(row);
        // }
        var dispaly = document.getElementById("filesDisplay");
        dispaly.innerHTML = "";

        var row = document.createElement('tr');
        dispaly.appendChild(row);
        row = document.createElement('tr');

        for (var i = 0; i < fileList.length; i++) {
            var per = fileList[i];

            if (per.fileType == 'directory') {
                row.innerHTML += "<td><a href='#' class='form-inline'><img src=\"../image/img_1.png\" width=\"75\" height=\"75\" data-type=\"directory\" filename="
                    + per.fileName + " date=" + per.date + " oncontextmenu=\"menuInfo(this)\" onclick=\"fileHandle(this)\"></img><p>" + per.fileName + "</p></a></td>";
                // + per.fileName+ " date="+per.date+" oncontextmenu=\"menuInfo(this)\" onclick=\"fileHandle(this)\"></img></a>";
            }

            if (per.fileType == 'file') {
                row.innerHTML += "<td><a href='#' class='form-inline'><img src=\"../image/img.png\" width=\"75\" height=\"75\" data-type=\"file\" filename="
                    + per.fileName + " date=" + per.date + " oncontextmenu=\"menuInfo(this)\" onclick=\"fileHandle(this)\"></img><p>" + per.fileName + "</p></a></td>";
            }

            if((i+1)% 4 == 0){
                dispaly.appendChild(row);
                row = document.createElement('tr');
            }
        }

        // if(!flag){
        if(row.innerHTML != ""){
            dispaly.appendChild(row);
        }
    }

    // 创建文件夹(test时候用的，现在是采用模态框输入)
    $('#makedir').on('click', function () {
        var filename = document.getElementById('dirPath').value;
        var path = sessionStorage.getItem("currentPath");
        // alert(path);
        var d = {
            "currentPath": path,
            "filename": filename,
        }
        var url = "/makeDir";
        $.ajax({
            type: "post",
            url: url,
            data: d,
            success: function (data) {
                // 清空之前的路径
                jQuery('#dirPath').val('');

                if (data.status == "isexist") {
                    alert("该文件夹已存在！")
                } else {
                    alert("创建成功！");
                    showFiles(data.fileList);
                    // var dispaly = document.getElementById("filesDisplay");
                    // dispaly.innerHTML = "";
                    // for (var i = 0;i<data.fileList.length;i++){
                    //     var per = data.fileList[i];
                    //     var row = document.createElement('div');
                    //     row.innerHTML="<div>"+ per.fileName + "  -----  "+per.date + "  -----  "+ per.fileType+"</div>";
                    //     dispaly.appendChild(row);
                    // }
                }
            }
        })
    })

    // 到指定文件目录的测试（test）
    $('#toOther').on('click', function () {
        var path = sessionStorage.getItem("currentPath");
        var newPath = "/rhy/file1";
        sessionStorage.setItem("currentPath", newPath);
        alert(newPath);
        var dispaly = document.getElementById("filesDisplay");
        dispaly.innerHTML = "";
        getFiles(newPath);
    })

    // 返回上一级目录
    $('#back').on('click', function () {
        var d = {
            "path": sessionStorage.getItem("currentPath")
        };
        var url = "/back";
        $.ajax({
            type: "post",
            url: url,
            data: d,
            success: function (data) {
                if (data.status == "ok") {
                    sessionStorage.setItem("currentPath", data.path);
                    document.getElementById("currentPathRecord").innerText = sessionStorage.getItem("currentPath");
                    showFiles(data.fileList);
                    // var dispaly = document.getElementById("filesDisplay");
                    // dispaly.innerHTML="";
                    // for (var i = 0;i<data.fileList.length;i++){
                    //     var per = data.fileList[i];
                    //     var row = document.createElement('div');
                    //     row.innerHTML="<div>"+ per.fileName + "  -----  "+per.date + "  -----  "+ per.fileType+"</div>";
                    //     dispaly.appendChild(row);
                    // }
                    sessionStorage.setItem("currentPath", data.path);
                } else {
                    alert("已是用户根目录!")
                }
            }
        })
    })

    // 退出登录
    $('#exit').on('click', function () {
        if (confirm("是否确定退出？")) {
            sessionStorage.removeItem("username");
            sessionStorage.removeItem("currentPath");
            document.location.href = "loginBetterOne.html";
        }
    })

</script>

</body>
</html>